package util

import "go-toy/constant"

type Message struct {
	Level   int
	Prefix  string
	Content string
}

/**
 * Set app message level
 * @param level int
 * @return *Message
 */
func (am *Message) SetLevel(level int) *Message {
	// Set level
	am.Level = level

	// Set prefix based on level
	am.Prefix = "APP"
	// Perfect prefix by level
	switch level {
	case constant.MsgLevelInfo:
		am.Prefix += " INFO"
	case constant.MsgLevelSuccess:
		am.Prefix += " SUCCESS"
	case constant.MsgLevelDebug:
		am.Prefix += " DEBUG"
	case constant.MsgLevelWarning:
		am.Prefix += " WARNING"
	case constant.MsgLevelError:
		am.Prefix += " ERROR"
	case constant.MsgLevelTrace:
		am.Prefix += " TRACE"
	case constant.MsgLevelFatal:
		am.Prefix += " FATAL"
	default:
		am.Prefix += " OTHER"
	}
	am.SetPrefix("[" + am.Prefix + "]")

	// return app message instance
	return am
}

/**
 * Get app message level
 * @return int
 */
func (am Message) GetLevel() int {
	return am.Level
}

/**
 * Set app message content
 * @param content string
 * @return *Message
 */
func (am *Message) SetPrefix(prefix string) *Message {
	am.Prefix = prefix
	return am
}

/**
 * Get app message prefix
 * @return string
 */
func (am Message) GetPrefix() string {
	return am.Prefix
}

/**
 * Set app message content
 * @return string
 */
func (am *Message) SetContent(content string) *Message {
	am.Content = content
	return am
}

/**
 * Get app message content
 * @return string
 */
func (am Message) GetContent() string {
	return am.Content
}

/**
 * Reset app message
 * @return void
 */
func (am *Message) Reset() {
	am.Level = 0
	am.Prefix = ""
	am.Content = ""
}
